package com.jzo2o.customer.controller.worker;

import com.jzo2o.common.expcetions.ForbiddenOperationException;
import com.jzo2o.common.model.CurrentUserInfo;
import com.jzo2o.common.utils.JwtTool;
import com.jzo2o.customer.model.domain.BankAccount;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.service.BankAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author DarkClown
 * @date 2024-08-19 19:17
 * @project_name jzo2o-customer
 * @parem
 **/
@RestController("workerBankAccountController")
@RequestMapping("/worker/bank-account")
@Api(tags = "服务端 - 设置银行账户接口设计")
public class BankAccountController {

    @Autowired
    BankAccountService bankAccountService;

    @Autowired
    JwtTool jwtTool;


    @PostMapping
    @ApiOperation("新增或更新银行账号信息接口")
    public void addOrUpdateBankAccount(@RequestBody BankAccount bankAccount,@RequestHeader("Authorization") String token) {
        //解析token
        CurrentUserInfo currentUserInfo = jwtTool.parseToken(token);
        //如果token为空,不能获取用户信息
        if (currentUserInfo == null) {
            throw new ForbiddenOperationException("token不能为空");
        }
        bankAccount.setId(currentUserInfo.getId());
        bankAccountService.saveOrUpdate(bankAccount);
    }

    @GetMapping("/currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号接口")
    public BankAccount currentUserBankAccount(@RequestHeader("Authorization") String token){
        return bankAccountService.currentUserBankAccount(token);
    }
}
